package com.hqyj.nacosdemo.provider.json;

//接口返回的json数据类型，自己的封装的。

import lombok.Data;

import java.io.Serializable;

@Data
//R ===>Response 表示是响应。
public class R implements Serializable, Cloneable {


    private static final Integer SUCCESS = 200;
    private static final Integer FAIL = 400;

    private static final Integer ERROR = 500;

    private Integer code; //响应返回的状态码
    private String msg; //响应返回的消息
    private Object data; //响应返回的数据
    private Object token; //响应返回的token对象，用来实现登录认证，我们暂时还用不到，这里保留。

    public static R success() {
        R r = new R();
        r.setCode(SUCCESS);
        r.setMsg("success");
        return r;
    }

    public static R success(String msg) {
        R r = new R();
        r.setCode(SUCCESS);
        r.setMsg(msg);
        return r;
    }

    public static R success(String msg, Object data) {
        R r = new R();
        r.setCode(SUCCESS);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static R success(String msg, Object data, Object token) {
        R r = new R();
        r.setCode(SUCCESS);
        r.setMsg(msg);
        r.setData(data);
        r.setToken(token);
        return r;
    }

    public static R fail() {
        R r = new R();
        r.setCode(FAIL);
        r.setMsg("failure");
        return r;
    }

    public static R fail(String msg) {
        R r = new R();
        r.setCode(FAIL);
        r.setMsg(msg);
        return r;
    }

    public static R error() {
        R r = new R();
        r.setCode(ERROR);
        r.setMsg("error");
        return r;
    }

    public static R error(String msg) {
        R r = new R();
        r.setCode(ERROR);
        r.setMsg(msg);
        return r;
    }

}
